package cn.app.exception;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authc.IncorrectCredentialsException;
import org.apache.shiro.authc.UnknownAccountException;
import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;

public class MyException implements HandlerExceptionResolver {

	@Override
	public ModelAndView resolveException(HttpServletRequest request,
			HttpServletResponse response, Object arg2, Exception ex) {
//		/判断是不是shiro的异常
		if(ex instanceof UnknownAccountException ||
		   ex instanceof IncorrectCredentialsException){
			//用户名或密码错误
			request.setAttribute("loginInfo", "用户名或密码错误");
			try {
				request.getRequestDispatcher("/index.jsp").forward(request, response);
			} catch (Exception e) {
				e.printStackTrace();
			}
			return new ModelAndView();
		}
		return null;
		
	}
	
	
}
